﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    >
    <!-- This Style redefines the ControlTemplate used by TreeViewItems and
       also provides a different itemspanel for their child items. -->
    <Style TargetType="TreeViewItem">
        <Style.Resources>
            <LinearGradientBrush x:Key="ItemAreaBrush" StartPoint="0.5, 0" EndPoint="0.5, 1" Opacity="0.3">
                <GradientStop Color="#EEFFFFFF" Offset="0" />
                <GradientStop Color="#22000000" Offset="1" />
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="SelectedItemAreaBrush" StartPoint="0.5, 0" EndPoint="0.5, 1" Opacity="0.4">
                <GradientStop Color="#22000000" Offset="0" />
                <GradientStop Color="#EEFFFFFF" Offset="1" />
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="MouseOverItemAreaBrush" StartPoint="0.5, 0" EndPoint="0.5, 1" Opacity="0.4">
                <GradientStop Color="LightSalmon" Offset="0" />
                <GradientStop Color="#EEFFFFFF" Offset="1" />
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="ItemBorderBrush" StartPoint="0.5, 0" EndPoint="0.5, 1">
                <GradientStop Color="LightGray" Offset="0" />
                <GradientStop Color="Gray" Offset="1" />
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="SelectedItemBorderBrush" StartPoint="0.5, 0" EndPoint="0.5, 1">
                <GradientStop Color="Gray" Offset="0" />
                <GradientStop Color="LightGray" Offset="1" />
            </LinearGradientBrush>
            <DropShadowBitmapEffect x:Key="DropShadowEffect" />
        </Style.Resources>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TreeViewItem">
                    <Grid Margin="1,1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>

                        <!-- This Border contains elements which display 
                 the content and child items of the TreeViewItem. -->
                        <Border Name="Bd" 
              Background="{StaticResource ItemAreaBrush}"
              BorderBrush="{StaticResource ItemBorderBrush}" 
              BorderThickness="0.6" 
              CornerRadius="8"              
              Padding="6"     
              SnapsToDevicePixels="True"
              >
                            <Grid>
                                <!-- Items with children are 
                     shown in an Expander. -->
                                <Expander Name="Exp" IsExpanded="{TemplateBinding TreeViewItem.IsExpanded}">
                                    <Expander.Header>
                                        <!-- Displays the item's header in the Expander. -->
                                        <ContentPresenter ContentSource="Header" />
                                    </Expander.Header>
                                    <!-- Displays the item's children. -->
                                    <ItemsPresenter />
                                </Expander>

                                <!-- Items without children are 
                     shown in a ContentPresenter. -->
                                <ContentPresenter Name="CntPres"
                  ContentSource="Header"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  Visibility="Collapsed" 
                  />
                            </Grid>
                        </Border>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- If the TreeViewItem has child items,
                 show it in an Expander.  Otherwise
                 hide the Expander and show the hidden
                 ContentPresenter. -->
                        <Trigger Property="TreeViewItem.HasItems" Value="false">
                            <Setter 
                TargetName="Exp" 
                Property="Visibility" 
                Value="Collapsed" />
                            <Setter 
                TargetName="CntPres" 
                Property="Visibility" 
                Value="Visible" />
                        </Trigger>

                        <!--When the item is selected in the TreeView, use the 
                "selected" colors and give it a drop shadow. -->
                        <Trigger Property="IsSelected" Value="true">
                            <Setter
                TargetName="Bd"
                Property="Panel.Background"                     
                Value="{StaticResource SelectedItemAreaBrush}" />
                            <Setter
                TargetName="Bd"
                Property="Border.BorderBrush"                     
                Value="{StaticResource SelectedItemBorderBrush}" />
                            <Setter
                TargetName="Bd"
                Property="TextElement.Foreground"                   
                Value="{DynamicResource 
                  {x:Static SystemColors.HighlightTextBrushKey}}" />
                            <Setter
                TargetName="Bd"
                Property="Border.BitmapEffect"                  
                Value="{StaticResource DropShadowEffect}" />
                        </Trigger>
                        <!--When the item is moused Over in the TreeView, use the 
                "selected" colors and give it a drop shadow. -->
                        <Trigger Property="IsMouseOver"  Value="true">
                            <Setter
                TargetName="Bd"
                Property="Panel.Background"                     
                Value="{StaticResource MouseOverItemAreaBrush}" />
                        </Trigger>
                        
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
         <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" >
                            <Image Name="img"  Width="20" Height="20" Stretch="Fill" 
                                      
                                       Source="{Binding 
                                       RelativeSource={RelativeSource 
                                       Mode=FindAncestor, 
                                       AncestorType={x:Type TreeViewItem}}, 
                                       Path=Header}" /> 
                                        <!--      Converter={x:Static local:MainListHeaderToImageConverter.Instance}}"  --> 
                            <TextBlock Text="{Binding}" Margin="5,0" />
                        </StackPanel>
                    </DataTemplate>
                </Setter.Value>
            </Setter>

    </Style>
</ResourceDictionary>